package com.example.chapter9sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyDbOpenHelper extends SQLiteOpenHelper {
    public MyDbOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE student(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "stuId INTEGER UNIQUE," +
                "stuName TEXT NOT NULL," +
                "stuClass TEXT);");
        db.execSQL("INSERT INTO student(stuId,stuName,stuClass) values (31,'大咖','数媒1993')");
        db.execSQL("INSERT INTO student(stuId,stuName,stuClass) values (33,'大咖','数媒1993')");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("DROP TABLE IF EXISTS student");
        onCreate(db);
    }
}
